package com.card.server.utils;

import com.card.server.config.RedisService;
import com.card.server.domain.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import reactor.core.publisher.FluxSink;

import java.util.*;

/**
 * @author TISNIW
 * @version 1.0
 * @date 2025/5/26 16:48
 * @desc
 */
@Component
public class RoomUtil {
    private static final Logger log = LoggerFactory.getLogger(RoomUtil.class);
    @Autowired
    private RedisService redisService;
    public void checkRoom() {
        // 1. 获取所有房间中信息
        for (int game = 1; game <= 1; game++) { // 示例只支持 game=1（斗地主）
            for (int table = 1; table <= 4; table++) {
                String poolKey = game + ":" + table + ":";
                Set<String> keys = redisService.getKeysByPattern(poolKey + "*");
                if (keys != null && !keys.isEmpty()) {
                    for (String key : keys) {
                        Room room = redisService.getCacheObject(key, Room.class);
                        Boolean isStarted = true;
                        for (Player player : room.getPlayers()){
                            if (player.getStatus() == 0){
                                isStarted = false;
                            }
                        }
                        if (isStarted == true){
                            room.setStatus(2);
                            sendStartUser(room.getPlayers());
                        }
                    }
                }
            }
        }
    }

    private void sendStartUser(List<Player> players) {
        for (Player player : players){

        }
    }
}
